#!/bin/sh
path = `pwd`
export LD_LIBRARY_PATH="$path":$LD_LIBRARY_PATH
PRO_NAME=ffmpegdemo

while true ; do
  DEAMON_NUM=`ps aux | grep deamon.sh | grep -v grep |wc -l`
   echo "deamon.sh =" $DEAMON_NUM 
  if [ "${DEAMON_NUM}" -gt "2" ]; then
    echo "deamon.sh is already started" 
    echo "If you want to reboot deamon.sh,please \"killall -9 deamon.sh\"" 	
    exit 0
  fi
  NUM=`ps aux | grep ${PRO_NAME} | grep -v grep |wc -l`
echo $NUM
chmod 777 *
  if [ "${NUM}" -lt "1" ];then
    echo "${PRO_NAME} was killed"
	 ./${PRO_NAME} 
 else
 #  elif [ "${NUM}" -gt "1" ];then
    echo "more than 1 ${PRO_NAME},killall ${PRO_NAME}"
    killall -9 $PRO_NAME
     ./${PRO_NAME}   
  fi

  NUM_STAT=`ps aux | grep ${PRO_NAME} | grep T | grep -v grep | wc -l`
  
  if [ "${NUM_STAT}" -gt "0" ];then
    killall -9 ${PRO_NAME}
	 ./${PRO_NAME} 
  fi
  
sleep 3s

done
 
exit 0
